#include "FBullet.h"


CFBullet::CFBullet()
{
	position_.x = START_COORDINATE_X;
	position_.y = START_COORDINATE_Y;

	// Center of circle
	positionCenter_.x = START_COORDINATE_X + R;
	positionCenter_.y = START_COORDINATE_Y + R;

	velocity_.x = 0.5f;
	velocity_.y = 0.5f;
	velocity_.z = 0.3f;

	fBulletShootStatus_ = SHOOT_STATUS;

	angle_ = 0.0f;

	LoadSprites();
}


CFBullet::~CFBullet()
{
}


void CFBullet::SetStartCoordinate(float x, float y)
{
	position_.x = x;
	position_.y = y;

	positionCenter_.x = x + R;
	positionCenter_.y = y + R;
}


void CFBullet::Render()
{
	spriteVector_[0]->Render(0, -1, position_);
}


void CFBullet::LoadSprites()
{
	spriteVector_.push_back(new CSprite(F_BULLET_IMAGE, 1, 1, 1));
}


void CFBullet::Update(DWORD deltaTime)
{
	if (fBulletShootStatus_ == SHOOT_0_RIGHT)
		Update0Right(deltaTime);

	if (fBulletShootStatus_ == SHOOT_0_LEFT)
		Update0Left(deltaTime);

	if (fBulletShootStatus_ == SHOOT_45_LEFT_DOWN)
		Update45LeftDown(deltaTime);

	if (fBulletShootStatus_ == SHOOT_45_LEFT_UP)
		Update45LeftUp(deltaTime);

	if (fBulletShootStatus_ == SHOOT_45_RIGHT_UP)
		Update45RightUp(deltaTime);

	if (fBulletShootStatus_ == SHOOT_45_RIGHT_DOWN)
		Update45RightDown(deltaTime);

	if (fBulletShootStatus_ == SHOOT_90_UP)
		Update90Up(deltaTime);

	if (fBulletShootStatus_ == SHOOT_90_DOWN)
		Update90Down(deltaTime);
}


void CFBullet::UpdateKeyBoard(CInput* inputDevice)
{
	if (inputDevice->KeyPress(DIK_A))
	{
		SetStartCoordinate(START_COORDINATE_X, START_COORDINATE_Y);
	}
}


void CFBullet::Update0Right(DWORD deltaTime)
{
	positionCenter_.x += velocity_.x * deltaTime;

	position_.x = positionCenter_.x + R * cos(angle_);
	position_.y = positionCenter_.y + R * sin(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}


void CFBullet::Update0Left(DWORD deltaTime)
{
	positionCenter_.x -= velocity_.x * deltaTime;

	position_.x = positionCenter_.x + R * sin(angle_);
	position_.y = positionCenter_.y + R * cos(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}


void CFBullet::Update45LeftDown(DWORD deltaTime)
{
	positionCenter_.x -= velocity_.x * deltaTime;
	positionCenter_.y -= velocity_.y * deltaTime;

	position_.x = positionCenter_.x + R * sin(angle_);
	position_.y = positionCenter_.y + R * cos(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}


void CFBullet::Update45LeftUp(DWORD deltaTime)
{
	positionCenter_.x -= velocity_.x * deltaTime;
	positionCenter_.y -= velocity_.y * deltaTime;

	position_.x = positionCenter_.x + R * sin(angle_);
	position_.y = positionCenter_.y + R * cos(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}


void CFBullet::Update45RightUp(DWORD deltaTime)
{
	positionCenter_.x += velocity_.x * deltaTime;
	positionCenter_.y -= velocity_.y * deltaTime;

	position_.x = positionCenter_.x + R * sin(angle_);
	position_.y = positionCenter_.y + R * cos(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}


void CFBullet::Update45RightDown(DWORD deltaTime)
{
	positionCenter_.x += velocity_.x * deltaTime;
	positionCenter_.y += velocity_.y * deltaTime;

	position_.x = positionCenter_.x + R * cos(angle_);
	position_.y = positionCenter_.y + R * sin(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}


void CFBullet::Update90Up(DWORD deltaTime)
{
	positionCenter_.y -= velocity_.y * deltaTime;

	position_.x = positionCenter_.x + R * cos(angle_);
	position_.y = positionCenter_.y + R * sin(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}


void CFBullet::Update90Down(DWORD deltaTime)
{
	positionCenter_.y += velocity_.y * deltaTime;

	position_.x = positionCenter_.x + R * cos(angle_);
	position_.y = positionCenter_.y + R * sin(angle_);
	positionCenter_.x++;
	angle_ += 0.5f;
}